﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace regex
{
	class Program
	{
		static void Main(string[] args)
		{
			if (args.Length < 2)
			{
				Console.WriteLine("USAGE:\r\nregex @FILENAME REGEX");
				return;
			}

			string text = null;
			string regex = null;

			foreach (string s in args)
			{
				if (s.StartsWith("@"))
				{
					text = File.ReadAllText(s.Substring(1));
				}
				else
				{
					regex = s;
				}
			}

			Match m = new Regex(regex).Match(text);

			foreach (Group g in m.Groups)
			{
				Console.WriteLine("{0}({1}): {2}", g.Index, g.Length, g.Value);
			}
		}
	}
}
